//- Copyright (C) 2018-2022 Chatopera Inc, <https://www.chatopera.com>
//- 
//- Licensed under the Apache License, Version 2.0 (the "License");
//- you may not use this file except in compliance with the License.
//- You may obtain a copy of the License at
//- 
//-  http://www.apache.org/licenses/LICENSE-2.0
//- 
//-  Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
extends /admin/include/layout.pug
block content
    .row
        .col-lg-12
            h1.site-h1(style='background-color:#FFFFFF;')
                | 数据表结构列表 #{size(propertiesList)}
                span(style='float:right;')
                    a.layui-btn.layui-btn-small.layui-btn-danger#batdel(href='javascript:void(0)', data-toggle='tip', data-title='删除数据表项同时会删除数据表元数据下的所有内容，请确认是否继续操作”？', title='删除数据表')
                        | 批量删除
                    if table && table.fromdb && table.listblocktemplet
                        a.layui-btn.layui-btn-small.layui-btn-danger(href="/admin/metadata/clean.html?id=" + table.id, id="batdel", data-toggle="tip", data-title="清空" + table.name + "存储在ES数据表里的所有数据，请确认是否继续操作？")
                        | 清空ES数据
                        a.layui-btn.layui-btn-small.layui-btn-danger(href="/admin/metadata/synctoes.html?id=" + table.id, id="batdel", data-toggle="tip", data-title="同步" + table.name + "数据库表到ES表，请确认是否继续操作？")
                        | 同步数据库表到ES表
                        a.layui-btn.layui-btn-small.layui-btn-danger(href="/admin/metadata/synctodb.html?id=" + table.id, id="batdel", data-toggle="tip", data-title="同步" + table.name + "的ES表到数据库表，请确认是否继续操作？")
                        | 同步数据库表到ES表
            .row(style='padding:5px;')
                .col-lg-12
                    table.layui-table(lay-skin='line')
                        thead
                            tr
                                th
                                    input#all(type='checkbox', onclick='$(".ids").prop("checked" , $(this).prop("checked"));')
                                th 标题
                                th 字段
                                th 校验
                                th 长度
                                th 关联
                                th 生成ID
                                th 多值
                                th 启用字典
                                th 禁用导入导出
                                th 流程变量
                                th(style='white-space:nowrap;', nowrap) 操作
                        tbody
                            for prop in propertiesList
                                tr
                                    td(style="width:1%;"): input(type="checkbox", class="ids", name="ids", value=prop.id)
                                    td= prop.name
                                    td= prop.fieldname + '(' + prop.datatypename + ')'
                                    td= prop.defaultvaluetitle
                                    td= prop.length
                                    td(align="center")
                                        if prop.reffk == true
                                            i.layui-icon(class="green") &#xe618;
                                    td(align="center")
                                        if prop.pk == true
                                            i.layui-icon(class="green") &#xe618;
                                    td(align="center")
                                        if prop.modits == true
                                            i.layui-icon(class="green") &#xe618;
                                    td(align="center")
                                        if prop.seldata == true
                                            i.layui-icon(class="green", title=prop.seldatacode) &#xe618;
                                    td(align="center")
                                        if prop.impfield == true
                                            i.layui-icon(class="green") &#xe618;
                                    td(align="center")
                                        if prop.systemfield == true
                                            i.layui-icon(class="green") &#xe618;
                                    td(style="white-space:nowrap;width:1%;" nowrap="nowrap")
                                        a(href="/admin/metadata/properties/edit.html?id=" + prop.id + "&p=" + (metadataList.number + 1), data-width="650" data-height="460" data-toggle="ajax" title="编辑" + table.name)
                                            i.layui-icon &#xe642;
                                            span 编辑
                                        a(href="/admin/metadata/properties/delete.html?id=" + prop.id + "&tbid=" + prop.dbtableid, data-toggle="tip", data-title="删除数据表项同时会删除数据表元数据下的所有内容，请确认是否删除数据表“" + prop.name + "”？" title="删除" + prop.name)
                                            i.layui-icon(style="color:red;") &#x1006;
                                            span 删除
    script.
        $(document).ready(function () {
            $('#batdel').click(function () {
                var ids = "";
                $('.ids').each(function () {
                    if ($(this).prop("checked")) {
                        if (ids != "") {
                            ids += "&";
                        }
                        ids += "ids=" + $(this).val();
                    }
                });
                $('#batdel').attr('href', '/admin/metadata/properties/batdelete.html?tbid=#{tbid}&' + ids);
            });
        });

